package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-06-03 15:02
 */
public class MergeAlternately {
    public String mergeAlternately(String word1, String word2) {

        char[] aChars = word1.toCharArray();
        char[] bChars = word2.toCharArray();
        StringBuilder sb = new StringBuilder();
        int i = 0;
        while (aChars.length > i && bChars.length > i) {
            sb.append(aChars[i]);
            sb.append(bChars[i]);
            i++;
        }
        if (aChars.length >= bChars.length) {
            for (int j = i; j < aChars.length; j++) {
                sb.append(aChars[j]);
            }
        } else {
            for (int j = i; j < bChars.length; j++) {
                sb.append(bChars[j]);
            }
        }
        return sb.toString();
    }
}
